Skip to content

Conversation

M-Moawad
Copy link
Contributor

The stackprot test currently depends on compiler-generated stack frame layouts, which can vary between toolchains and optimization levels. This makes the overflow check fragile and may cause unintended faults.

Add a small guard buffer in alternate_thread so the intentional overflow is always contained within the thread stack. This ensures the test behaves consistently across toolchains, architectures, and optimization settings.

Fixes: #95060

@sonarqubecloud
Copy link

@M-Moawad
Copy link
Contributor Author

@ceolin @dcpleung Could you take a look at the issue #95060 and this PR?

* MPU-protected region. Required to make the test independent of compiler-
* specific stack frame layouts.
*/
volatile char overflow_guard_area[32] = "Forcing Initialization!";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to make this __used so compiler won't complain about this not being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using __used gives the following warning:

zephyr/tests/kernel/mem_protect/stackprot/src/main.c:87:11: warning: '__used__' attribute only applies to variables with non-local storage, functions, and Objective-C methods [-Wignored-attributes]
   87 |         volatile __used char overflow_guard_area[32] = "Forcing Initialization!";
      |                  ^
zephyr/include/zephyr/toolchain/gcc.h:278:32: note: expanded from macro '__used'
  278 | #define __used          __attribute__((__used__))
      |                                        ^
1 warning generated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... let's hope that compilers (other than those in Zephyr SDK) are not going to complain about it not being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using __unused makes both Zephyr SDK and ARCMWDT happy!

dcpleung
dcpleung previously approved these changes Sep 24, 2025
* MPU-protected region. Required to make the test independent of compiler-
* specific stack frame layouts.
*/
volatile char overflow_guard_area[32] = "Forcing Initialization!";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... let's hope that compilers (other than those in Zephyr SDK) are not going to complain about it not being used.

@M-Moawad
Copy link
Contributor Author

@cfriedt Could you review this fix and the related issue?

cfriedt
cfriedt previously approved these changes Oct 1, 2025
@M-Moawad M-Moawad dismissed stale reviews from cfriedt and dcpleung via 10cd0c2 October 19, 2025 10:26
@M-Moawad M-Moawad force-pushed the moawad-fix-stackprot-test-with-nsim_em branch from 1b49504 to 10cd0c2 Compare October 19, 2025 10:26
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 19, 2025
@zephyrbot zephyrbot requested a review from nashif October 19, 2025 10:28
The stackprot test currently depends on compiler-generated stack frame
layouts, which can vary between toolchains and optimization levels.
This makes the overflow check fragile and may cause unintended faults.

Add a small guard buffer in alternate_thread so the intentional overflow
is always contained within the thread stack. This ensures the test
behaves consistently across toolchains, architectures, and optimization
settings.

Signed-off-by: Mohamed Moawad <[email protected]>
@M-Moawad M-Moawad force-pushed the moawad-fix-stackprot-test-with-nsim_em branch from 10cd0c2 to d0e57f3 Compare October 20, 2025 10:49
@sonarqubecloud
Copy link

@M-Moawad M-Moawad requested a review from cfriedt October 22, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Tests Issues related to a particular existing or missing test area: Userspace Userspace

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/kernel/mem_protect/stackprot: test_create_alt_thread fails on ARC nsim_em due to MPU exception at thread stack boundary

4 participants